<template>
    <NavBack title="注册"></NavBack>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="password"
          :type="passtype"
          name="password"
          label="密码"
          placeholder="密码"
          required
          :right-icon="eyeicon"
          :rules="[{ required: true, message: '请填写密码' }]"
          @click-right-icon="showPass"
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button round block type="primary" native-type="submit">
          注册
        </van-button>
      </div>
    </van-form>
  </template>
  
  <script>
  import { showSuccessToast, showFailToast } from "vant";
  import NavBack from "../../components/NavBack.vue";
  
  export default {
    name: "Pass",
    components:{NavBack},
    data() {
      return {
        eyeicon: "closed-eye",
        passtype: "password",
        password: "",
      };
    },
    methods: {
      showPass() {
        if (this.eyeicon === "closed-eye") {
          this.eyeicon = "eye-o";
          this.passtype = "text";
        } else {
          this.eyeicon = "closed-eye";
          this.passtype = "password";
        }
      },
      onSubmit(value) {
        this.$http({
          url: "/user/dofinishregister",
          method: "post",
          data:{
            tel:this.$route.query.tel,
            password:value.password
          },
        }).then((res) => {
          if (res.data.code === "200") {
            showSuccessToast("注册成功！");
            this.$router.push({
              path:"/Login"
            });
          }
        });
      }
    },
  };
  </script>
  
  <style>
  </style>